/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.component.page;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JPanel;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.factory.ImageFactory;

/**
 * 说明：
 * 翻页组件  实现翻页的页面，都必须添加此面板
 * @Author：李智深
 * @Date：2012-03-14
 */
public class PagingComponent extends JPanel implements MouseListener{

	private static final long serialVersionUID = 1L;
	private JLabel homePage=new JLabel("首页");;//首页
	private JLabel prevPage=new JLabel("上一页 ");;//上一页 
	private JLabel nextPage=new JLabel("下一页");;//下一页
	private JLabel lastPage=new JLabel("尾页");;//尾页
	private JLabel info=new JLabel("      当前第 0 页/共 0 页      ");;
	private PageDelegale pageDelegale;
	private Cursor handCursor=new Cursor(Cursor.HAND_CURSOR);
	private Color color=new Color(2,101,164);
	public PagingComponent(){
		this.setOpaque(false);
		this.setLayout(new FlowLayout(FlowLayout.RIGHT));
		this.initView();
		this.initListener();
	}
	
	private void initView(){
		homePage.setCursor(handCursor);
		prevPage.setCursor(handCursor);
		nextPage.setCursor(handCursor);
		lastPage.setCursor(handCursor);
		homePage.setFont(Util.FONT_PLAIN_13);
		prevPage.setFont(Util.FONT_PLAIN_13);
		nextPage.setFont(Util.FONT_PLAIN_13);
		lastPage.setFont(Util.FONT_PLAIN_13);
		info.setFont(Util.FONT_PLAIN_13);
		this.add(new JLabel(ImageFactory.loadImage(ImageFactory.ICON_5)));
		this.add(homePage);
		this.add(prevPage);
		this.add(nextPage);
		this.add(lastPage);
		this.add(new JLabel(ImageFactory.loadImage(ImageFactory.ICON_6)));
		this.add(info);
		
	}
	private void initListener(){
		homePage.addMouseListener(this);
		prevPage.addMouseListener(this);
		nextPage.addMouseListener(this);
		lastPage.addMouseListener(this);
	}
	public void show(){
		info.setText("      "+pageDelegale.getInfo()+"      ");
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		if(e.getSource()==homePage){
			pageDelegale.homePage();
		}else if(e.getSource()==prevPage){
			pageDelegale.prevPage();
		}else if(e.getSource()==nextPage){
			pageDelegale.nextPage();
		}else if(e.getSource()==lastPage){
			pageDelegale.lastPage();
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		if(e.getSource()==homePage){
			homePage.setForeground(color);
		}else if(e.getSource()==prevPage){
			prevPage.setForeground(color);
		}else if(e.getSource()==nextPage){
			nextPage.setForeground(color);
		}else if(e.getSource()==lastPage){
			lastPage.setForeground(color);
		}
	}

	@Override
	public void mouseExited(MouseEvent e) {
		if(e.getSource()==homePage){
			homePage.setForeground(Color.BLACK);
		}else if(e.getSource()==prevPage){
			prevPage.setForeground(Color.BLACK);
		}else if(e.getSource()==nextPage){
			nextPage.setForeground(Color.BLACK);
		}else if(e.getSource()==lastPage){
			lastPage.setForeground(Color.BLACK);
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}

	public PageDelegale getPageDelegale() {
		return pageDelegale;
	}

	public void setPageDelegale(PageDelegale pageDelegale) {
		this.pageDelegale = pageDelegale;
	}
}
